//
//  MainTabBarViewController.m
//  YunJiaBaoFirst
//
//  Created by 腾云小白龍 on 16/7/13.
//  Copyright © 2016年 腾云小白龍. All rights reserved.
//

#import "MainTabBarViewController.h"
#import "MainNavigationViewController.h"
#import "YJBChatViewController.h"
#import "YJBTradeMarketViewController.h"
#import "YJBContactListViewController.h"
#import "YJBPersonalInfoViewController.h"

@interface MainTabBarViewController ()

@end

@implementation MainTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initChildViewController];
}

-(void)initChildViewController{
    
    YJBTradeMarketViewController *tradeVc = [[YJBTradeMarketViewController alloc]init];
    [self addChildViewController:tradeVc withTitle:@"市场" imageName:@"tab_bar_status" selectImageName:@"tab_bar_status_selected"];

    
    YJBChatViewController *chatVc = [[YJBChatViewController alloc]init];
    [self addChildViewController:chatVc withTitle:@"车谈" imageName:@"tab_bar_message_default" selectImageName:@"tab_Bar_Message_sel"];
    
    YJBContactListViewController *contactVc = [[YJBContactListViewController alloc]init];
    [self addChildViewController:contactVc withTitle:@"通讯录" imageName:@"ic_contacts" selectImageName:@"ic_contacts_default"];
    
    YJBPersonalInfoViewController *personalVc = [[YJBPersonalInfoViewController alloc]init];
    [self addChildViewController:personalVc withTitle:@"我" imageName:@"tab_bar_personal_icon" selectImageName:@"tab_bar_personal_icon_selected"];
}

-(void)addChildViewController:(UIViewController *)childController withTitle:(NSString*)title imageName:(NSString *)imageName selectImageName:(NSString *)selectedImageName{
    
    childController.title = title;
    childController.tabBarItem.image = [UIImage imageNamed:imageName];
    //设置mode 让选中的图片为原图片颜色 而不是 系统默认的蓝色
    childController.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    MainNavigationViewController *vc = [[MainNavigationViewController alloc]initWithRootViewController:childController];
    childController.navigationController.navigationBar.hidden = YES;
    [self addChildViewController:vc];
//    [self initUIBarButtonItemProperty];
}

#pragma mark -- 更改tabbar button 的 字体颜色;
- (void)initUIBarButtonItemProperty {
    UITabBarItem * item = [UITabBarItem appearance];
    NSMutableDictionary * textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = TAB_BAR_ITEM_COLOR;
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    NSMutableDictionary * textSelectedAttrs = [NSMutableDictionary dictionary];
    textSelectedAttrs[NSForegroundColorAttributeName] = MAIN_COLOR;
    textSelectedAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    [item setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:textSelectedAttrs forState:UIControlStateSelected];
}

#pragma mark -- navigationBar 默认颜色
- (void)initUINavigationBarProperty {
    UINavigationBar * bar = [UINavigationBar appearance];
    NSMutableDictionary * barTextAttr = [NSMutableDictionary dictionary];
    barTextAttr[NSFontAttributeName] = [UIFont systemFontOfSize:18];
    barTextAttr[NSForegroundColorAttributeName] = [UIColor whiteColor];
    [bar setTitleTextAttributes:barTextAttr];
    [bar setBarTintColor:MAIN_COLOR];
    [bar setTintColor:[UIColor whiteColor]];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
